
#include "com_msg.h"
#include "page_base.h"
#include "page_manager.h"
#include "img_common.h"
#include "pt_ipc.h"
#include "pt_info.h"
#include "pt_dev.h"
#include "sys_font.h"
#include "pt_fs.h"

static ui_com_msg_t  ui_com_msg;


static void com_msg_die_timer_callback(struct _lv_timer_t *t)
{
    ui_com_msg_destroy();
}

int ui_com_msg_create(int timeout,const char* string)
{
    //**********************************************************************************************
    if(!ui_com_msg.bg_txt){
        ui_com_msg.bg_txt = lv_obj_create(lv_scr_act());
    }
    lv_obj_set_pos(ui_com_msg.bg_txt,35,234);
    lv_obj_set_size(ui_com_msg.bg_txt,408,60);

	lv_obj_set_style_radius(ui_com_msg.bg_txt, 30, LV_PART_MAIN);
	lv_obj_set_style_border_width(ui_com_msg.bg_txt, 0, LV_PART_MAIN);
	lv_obj_set_style_border_color(ui_com_msg.bg_txt, lv_color_make(0x00, 0x00, 0x00), LV_PART_MAIN);
	lv_obj_set_style_border_opa(ui_com_msg.bg_txt, LV_OPA_0, LV_PART_MAIN);

	lv_obj_set_style_outline_width(ui_com_msg.bg_txt, 0, LV_PART_MAIN);
	lv_obj_set_style_shadow_width(ui_com_msg.bg_txt, 0, LV_PART_MAIN);
	lv_obj_set_scrollbar_mode(ui_com_msg.bg_txt, LV_SCROLLBAR_MODE_OFF);
	lv_obj_set_style_pad_all(ui_com_msg.bg_txt, 0,0);

    #if 0
    lv_obj_set_style_bg_opa(ui_com_msg.bg_txt,LV_OPA_0,0);
    #else
    lv_obj_set_style_bg_opa(ui_com_msg.bg_txt,LV_OPA_80,0);
    lv_obj_set_style_bg_color(ui_com_msg.bg_txt,lv_color_make(0xff,0xff,0xff),0);
    #endif
    //**********************************************************************************************

    if(!ui_com_msg.txt){
        ui_com_msg.txt = lv_label_create(ui_com_msg.bg_txt);
    }
    lv_obj_set_pos(ui_com_msg.txt,0,10);
    lv_obj_set_size(ui_com_msg.txt,400,30);
    lv_obj_set_style_text_align(ui_com_msg.txt,LV_TEXT_ALIGN_CENTER,0);
    lv_obj_set_style_text_opa(ui_com_msg.txt,LV_OPA_100,LV_PART_MAIN);
    lv_obj_set_style_text_color(ui_com_msg.txt,lv_color_make(0x33,0x33,0x33),LV_PART_MAIN);
    lv_obj_set_style_text_font(ui_com_msg.txt, lv_font_get(24), LV_STATE_DEFAULT);

    lv_label_set_text(ui_com_msg.txt,string);
    //**********************************************************************************************
    if(!timeout){
        timeout = 6000;
    }
    if(!ui_com_msg.die_timer){
        ui_com_msg.die_timer = lv_timer_create(com_msg_die_timer_callback,timeout,NULL);
    }else{
        lv_timer_reset(ui_com_msg.die_timer);
    }
    //**********************************************************************************************

    return 0;

}

int ui_com_msg_destroy(void)
{
    if(ui_com_msg.die_timer){
        lv_timer_del(ui_com_msg.die_timer);
        ui_com_msg.die_timer = NULL;
    }

    if(ui_com_msg.bg_txt){
        lv_obj_del(ui_com_msg.bg_txt);
        ui_com_msg.bg_txt = NULL;
        ui_com_msg.txt    = NULL;
    }

    return 0;
}


static void com_msg_on_custom_attr_config(page_base_t* self)
{


}
static void com_msg_on_view_load(page_base_t* self)
{


}
static void com_msg_on_view_did_load(page_base_t* self)
{


}
static void com_msg_on_view_will_appear(page_base_t* self)
{


}
static void com_msg_on_view_did_appear(page_base_t* self)
{


}
static void com_msg_on_view_will_disappear(page_base_t* self)
{


}
static void com_msg_on_view_did_disappear(page_base_t* self)
{


}
static void com_msg_on_view_did_unload(page_base_t* self)
{


}

static page_vtable_t page_com_msg_param = {

    .on_custom_attr_config  = com_msg_on_custom_attr_config,
    .on_view_load           = com_msg_on_view_load,
    .on_view_did_load       = com_msg_on_view_did_load,
    .on_view_will_appear    = com_msg_on_view_will_appear,
    .on_view_did_appear     = com_msg_on_view_did_appear,
    .on_view_will_disappear = com_msg_on_view_will_disappear,
    .on_view_did_disappear  = com_msg_on_view_did_disappear,
    .on_view_did_unload     = com_msg_on_view_did_unload,
};


page_vtable_t* lv_page_com_msg_create(void)
{
    return &page_com_msg_param;
}
